﻿using System;
using System.IO;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using ZilLion.Service.Core.ConfigManager.Manager;
using ZilLion.Service.Core.Infrastructure;

namespace ZilLion.Service.Core.App
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
            Console.ReadKey();
        }

        public static IWebHost BuildWebHost(string[] args)
        {
            var port = ZilLionConfigurationManager.GetConfigInstance<WebApiAppConfig>().SelfHostPort;
            Console.WriteLine($"http://localhost:{port}");
            return WebHost.CreateDefaultBuilder().UseKestrel().UseUrls($"http://localhost:{port}")
                .ConfigureServices(services => services.AddAutofac())
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
        }
    }
}